/**
 * 类 class
 *  ts声明一个类的时候，
 *
 * */

class Person {
    //类的静态属性，可以直接通过类名.属性来调用
    static age:string = 'ygg'

    name: string;

    getName(): void {
        console.log(this.name , Person.age)
    }
}

//修改静态属性：
let girlMaker :typeof Person = Person
girlMaker.age = 'hey boy';

let girl:Person = new girlMaker();
console.log(girl.getName())


// Person是实例的类型
let p: Person = new Person();
p.name = 'zhangsan';
p.getName();   //zhangsan


//存取器
class User {
    //最好提前在这里声明好这些属性
    public readonly PI = 3.14;
    // myName:string = ''
    //public 可以代替声明和赋值
    constructor(public myName: string) {
        // this.myName = myName
    }

    get name() {
        return this.myName
    }

    set name(value) {
        this.myName = value.toUpperCase()
    }
}

let user = new User('zhangsan');   //赋了初始值，
console.log(user.name);  // zhangsan

// user.PI = 3.15   只读属性
/**
 * readonly  ：编译阶段检查
 * const：运行阶段的检查
 * */


//public不能修饰类

class Father {
    public name: string;   //   public:该属性可以被自己类本身，子类和其他类访问
    protected age: number;    //  protected:类本身和子类可以访问，其他类不可以访问
    private money: number   //  private：只能自身访问，子类和其他类不能被访问
    constructor(name: string, age: number, money: number) {
        this.name = name;
        this.age = age;
        this.money = money
    }

    getName() {

    }

    getAge() {

    }

    getMoney() {

    }

}


class Child extends Father {
    constructor(name: string, age: number, money: number) {
        super(name, age, money);
        console.log(this.age)
    }
}


let child = new Child('zhangsan', 1, 2);
child.getName();
child.getAge();
// child.age;


//类--存储器实现


let passCode = 'secret1 correct';

class Employee {
    private _fullName: string

    // tsc demo.ts --target es5
    get FullName(): string {
        return this._fullName
    }

    set FullName(newName: string) {
        if (passCode && passCode === 'secret correct') {
            this._fullName = newName
        } else {
            console.log('Error:报错!')

        }
    }

}

let employee = new Employee();
employee.FullName = 'fork';
if (employee.FullName) {
    console.log(employee.FullName)
}






